package com.echoesnet.echoesshortvideo.Repositories;

import com.echoesnet.echoesshortvideo.Api.HttpMethods;
import com.echoesnet.echoesshortvideo.Api.RequestHeader;
import com.echoesnet.echoesshortvideo.AppController;
import com.echoesnet.echoesshortvideo.Persistence.AppDatabase;
import com.echoesnet.echoesshortvideo.Persistence.CommentListDao;

import java.util.Map;

import io.reactivex.Observer;

/**
 * Copyright (C) 2018 科技发展有限公司
 * 完全享有此软件的著作权，违者必究
 * 负责数据处理
 *
 * @author ben
 * @version 1.0
 * @modifier
 * @createDate 2018/4/19 18:12
 * @description
 */
//@Singleton
public class CommentListRepository
{
    private final String TAG = CommentListRepository.class.getSimpleName();

    private final CommentListDao infoDao;

    //@Inject
    public CommentListRepository()
    {
        this.infoDao = AppDatabase.getInstance(AppController.getInstance()).commentListDao();
    }

    /**
     * 获取评论列表
     *
     * @param observer
     */
    public void getCommentList(String interfaceName, String videoId, int start, int step, Observer<String> observer)
    {
        Map<String, Object> reqMap = RequestHeader.getCommonPartOfParam();
        reqMap.put(RequestHeader.VIDEO_ID, videoId);
        reqMap.put(RequestHeader.INDEX, start);
        reqMap.put(RequestHeader.NUM, start + step);
        HttpMethods.getInstance().startServerRequest(observer, interfaceName, reqMap, true);
    }

    /**
     * 评论点赞
     *
     * @param observer
     */
    public void likeComment(String interfaceName, String commentId, Observer<String> observer)
    {
        Map<String, Object> reqMap = RequestHeader.getCommonPartOfParam();
        reqMap.put(RequestHeader.COMMENT_ID, commentId);
        HttpMethods.getInstance().startServerRequest(observer, interfaceName, reqMap, true);
    }

    /**
     * 评论
     *
     * @param interfaceName
     * @param videoId
     * @param commentContent
     * @param observer
     */
    public void commentVideo(String interfaceName, String videoId, String commentContent, Observer<String> observer)
    {
        Map<String, Object> reqMap = RequestHeader.getCommonPartOfParam();
        reqMap.put(RequestHeader.VIDEO_ID, videoId);
        reqMap.put(RequestHeader.COMMENT, commentContent);
        HttpMethods.getInstance().startServerRequest(observer, interfaceName, reqMap, true);

        //return userDao.loadVideosByIds();
    }

    /**
     * 回复评论
     *
     * @param interfaceName
     * @param videoId
     * @param commentContent
     * @param observer
     */
    public void replyComment(String interfaceName, String videoId, String commentContent, String commentId, Map<String, String> replyUserInfo, Observer<String> observer)
    {
        Map<String, Object> reqMap = RequestHeader.getCommonPartOfParam();
        reqMap.put(RequestHeader.VIDEO_ID, videoId);
        reqMap.put(RequestHeader.COMMENT, commentContent);
        reqMap.put(RequestHeader.COMMENT_ID, commentId);
        String userInfo = AppController.getGsonInstance().toJson(replyUserInfo);
        reqMap.put(RequestHeader.COMMENT_USER_INFO, userInfo);

        HttpMethods.getInstance().startServerRequest(observer, interfaceName, reqMap, true);

        //return userDao.loadVideosByIds();
    }

    /**
     * 删除评论
     *
     * @param observer
     */
    public void deleteComment(String interfaceName, String commentId, Observer<String> observer)
    {
        Map<String, Object> reqMap = RequestHeader.getCommonPartOfParam();
        reqMap.put(RequestHeader.COMMENT_ID, commentId);
        HttpMethods.getInstance().startServerRequest(observer, interfaceName, reqMap, true);
    }

}
